//
//  EFADeviceModel.h
//  efairy
//
//  Created by XiangDongMBP on 2017/7/26.
//  Copyright © 2017年 East. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <YYModel.h>
#import <UIKit/UIKit.h>

#pragma mark - 设备列表
@interface EFADevPjtUserInfo : NSObject
@property (nonatomic, assign) NSInteger efairyuser_id;              ///< 负责人编号
@property (nonatomic, copy)   NSString *efairyuser_nickname;        ///< 负责人姓名
@property (nonatomic, copy)   NSString *efairyuser_phonenumber;     ///< 负责人联系号码
@end

@interface EFADeviceListItem : NSObject<YYModel, NSCoding>
@property (nonatomic, assign) NSInteger efairydevice_id;            //!< 设备编号
@property (nonatomic, copy)   NSString *efairydevice_uuid;          //!< 设备唯一编号
@property (nonatomic, copy)   NSString *efairydevice_name;          //!< 设备名称
@property (nonatomic, copy)   NSString *efairydevice_install_time;  //!< 安装时间
@property (nonatomic, copy)   NSString *efairydevice_description;   //!< 设备描述
@property (nonatomic, copy)   NSString *efairydevice_address;       //!< 地址
@property (nonatomic, assign) double efairydevice_location_lat;     //!< 纬度(小数点6位)
@property (nonatomic, assign) double efairydevice_location_lng;     //!< 经度(小数点6位)
@property (nonatomic, assign) NSInteger efairydevice_project_id;    //!< 所属项目ID
@property (nonatomic, copy)   NSString *efairydevice_project_name;  //!< 设备名称
@property (nonatomic, assign) BOOL efairydevice_is_online;          //!< 是否在线，0-否 1-是
@property (nonatomic, assign) NSInteger efairydevice_belong_system; //!< 系统类型，具体状态参考《网络传输协议-表4》
@property (nonatomic, assign) NSInteger efairydevice_device_type_id;//!< 设备类型，具体状态参考《网络传输协议-表5》
// 设备状态，具体状态参考《网络传输协议》设备状态，0-离线 1-火警 2-预警 3-故障 4-启动 5-屏蔽 6-正常
@property (nonatomic, assign) NSInteger efairydevice_state;         //!< 设备状态，(改为参考下面列表)
@property (nonatomic, assign) NSInteger efairydevice_alarm_id;      //!< 0-离线 1-火警 2-预警 3-故障 4-启动 5-屏蔽 6-正常
@property (nonatomic, assign) NSInteger efairydevice_version;       //!< 设备软件版本号2
@property (nonatomic, copy)   NSString *efairydevice_version_date;  //!< 设备软件版本号1
@property (nonatomic, assign) NSInteger efairydevice_csq;          //信号强度值
@property (nonatomic, assign) NSInteger efairydevice_csq_level;    //信号强度0-弱 1-中 2-强

// 项目管理-新增变量
@property (nonatomic, assign) BOOL efairydevice_user_ownned;  //!< 用户是否拥有该设备，0-否 1-是
@property (nonatomic, strong) NSMutableArray<NSString *> *efairydevice_imgurl_list;         ///< 设备竣工图
@property (nonatomic, strong) NSArray<EFADevPjtUserInfo *> *efairyproject_user_info_list;   ///< 项目负责人相关信息
@property (nonatomic, strong) NSArray<EFADevPjtUserInfo *> *efairydevice_user_info_list;    ///< 设备用户的相关信息

// 自定义变量
@property (nonatomic, copy)   NSString *efairydevice_device_type_name;  ///< 设备类型名称(用于添加设备、编辑设备)
@property (nonatomic, copy)   NSString *efairydevice_main_uuid;         ///< 设备主编码(用于添加设备、编辑设备)
@property (nonatomic, copy)   NSString *efairydevice_sub_uuid;          ///< 设备从编码(用于添加设备、编辑设备)
// 自定义函数
@property (nonatomic, readonly) NSString *ccid;             ///< 设备主ID
@property (nonatomic, readonly) NSString *uuid_address;     ///< 设备从ID
@property (nonatomic, readonly) NSString *map_state_str;    ///< 用于地图上副标题
@property (nonatomic, readonly) NSString *mapImgName;       ///< 地图图标
@property (nonatomic, readonly) NSString *listImgName;      ///< 列表图标
@property (nonatomic, readonly) NSString *map_state_color;  ///< 地图的颜色
@property (nonatomic, readonly) NSString *three_state_str;  ///< 三种文字描述
@property (nonatomic, readonly) NSAttributedString *three_state_attStr; ///< 带有颜色的文字描述
- (void)refreshDeviceTypeName;  ///< 由设备类型，刷新设备类型名称、设备从ID
- (void)composeToUUID;          ///< 设备主从编码组合成设备UUID
- (void)deComposeUUID;          ///< 设备UUID分解成子UUID
@end
@interface EFADeviceModel : NSObject<YYModel, NSCoding>
@property (nonatomic, assign) NSInteger total_rows;
@property (nonatomic, strong) NSMutableArray<EFADeviceListItem *> *device_list;

@property (nonatomic, readonly) BOOL isWholeSel;  ///< 是否全选
@property (nonatomic, readonly) BOOL totalLoad;
@property (nonatomic, readonly) BOOL totalZero;
@property (nonatomic, readonly) NSArray<EFADeviceListItem *> *ownnedDeviceArray;
@property (nonatomic, readonly) NSArray<NSNumber *> *idListArray;
@property (nonatomic, readonly) NSArray<EFADeviceListItem *> *normalDeviceArray;
@property (nonatomic, readonly) NSArray<EFADeviceListItem *> *faultDeviceArray;
@property (nonatomic, readonly) NSArray<EFADeviceListItem *> *alarmDeviceArray;
- (instancetype)initWithListArray:(NSArray<EFADeviceListItem *> *)array;
- (void)addMoreWithData:(EFADeviceModel *)temp;
- (void)wholeDeviceSelectOrNot:(BOOL)sel;
@end

#pragma mark - 新增、编辑设备
@interface EFADevPubItem : NSObject
@property (nonatomic, strong) UIImage *img;         ///< 缩略图
@property (nonatomic, strong) NSData *originalData; ///< 原图数据
@property (nonatomic, copy)   NSString *content;    ///< 图片描述
@property (nonatomic, copy)   NSString *image_url;  ///< 上传之后得到的图片连接
@property (nonatomic, assign) BOOL canEdit;         ///< 可编辑or不可编辑

- (instancetype)initWithImage:(UIImage *)img originalData:(NSData *)data imgUrl:(NSString *)url canEdit:(BOOL)canEdit;
@end

@interface EFADevPubModel : NSObject
@property (nonatomic, strong) NSMutableArray<EFADevPubItem *> *image_list;  ///< 图片列表
@property (nonatomic, assign) NSInteger imgMaxCnt;              ///< 最多可以选择照片的数量
///< 自定义函数
@property (nonatomic, readonly) BOOL isEmpty;                   ///< 检查是否有用户输入
@property (nonatomic, readonly) BOOL isImgUpload;               ///< 图片是否已经上传
@property (nonatomic, readonly) NSArray<UIImage *> *needUploadImgArray; ///< 需要上传的缩略图数组
@property (nonatomic, readonly) NSArray<UIImage *> *imgArray;           ///< 缩略图数组
@property (nonatomic, readonly) NSArray<NSString *> *urlArray;          ///< 上传之后的图片连接

- (instancetype)initWithImgUrlArray:(NSArray<NSString *> *)urlArray canEdit:(BOOL)canEdit;
- (void)addPublishItemsWithImgArray:(NSArray<UIImage *> *)imgArray originalDataArray:(NSArray<NSData *> *)dataArray;
- (void)removePublishItemAtIndex:(NSInteger)index;
- (void)updateImgUrlWithArray:(NSArray<NSString *> *)array;
@end


#pragma mark - 设备信息
@interface EFADevPtCidItem : NSObject
@property (nonatomic, assign) NSInteger pt;
@property (nonatomic, strong) NSMutableArray<NSNumber *> *cidArray;
@property (nonatomic, assign) NSInteger thv;

- (instancetype)initWithPt:(NSInteger)pt cid:(NSInteger)cid thv:(NSInteger)thv;
- (NSString *)cidTitleWithCid:(NSNumber *)cid;
- (NSInteger)cidDisplayWithCid:(NSNumber *)cid;
@end

//设备阈值的最大值最小值
@interface ValueRange : NSObject
@property (nonatomic,copy) NSString *name;
@property (nonatomic,assign) NSInteger value;
@end

@interface EFADevRealTimeDataItem : NSObject
@property (nonatomic, assign) NSInteger cid;    //!< 通道号
@property (nonatomic, assign) NSInteger rtv;    //!< 实时值
@property (nonatomic, assign) CGFloat thv;    //!< 阈值
@property (nonatomic, assign) NSInteger st;     //!< 设备状态，具体参考《网络传输协议-表6》
@property (nonatomic, assign) NSInteger pt;     //!< 参量类型，具体参考《网络传输协议-表7》
// 新增属性
@property (nonatomic, assign) NSInteger max;    ///< 阈值起始值(服务器返回)
@property (nonatomic, assign) NSInteger min;    ///< 阈值终止值(服务器返回)
@property (nonatomic,copy) NSString *unit;      ///< 单位(服务器返回)
@property (nonatomic,copy) NSString *c_name;    ///< 通道名(服务器返回)
@property (nonatomic, assign) NSInteger value_type; ///< 1输入模式，2选择模式
@property (nonatomic, strong) NSMutableArray<ValueRange *> *value_range;//最大值 和最小值



// 自定义函数
@property (nonatomic, readonly) NSInteger cidDisplay; ///< 显示的通道号
@property (nonatomic, readonly) NSString *cidTitle;   ///< 通道名称
@property (nonatomic, readonly) NSString *rtvValue;   //!< 通道值(带有单位、阈值)
@property (nonatomic, readonly) NSString *thvValue;   ///< 阈值(带有单位)
@property (nonatomic, readonly) NSInteger thvStart;   ///< 阈值起始值(已进行倍率的换算)
@property (nonatomic, readonly) NSInteger thvEnd;     ///< 阈值终止值(已进行倍率的换算)
@property (nonatomic, readonly) NSString *ptUnit;     ///< 单位
- (void)configThv:(NSInteger)thv;                     ///< 这里需要进行倍率换算
@end

@interface EFADevRealTimeData : NSObject
@property (nonatomic, assign) NSInteger ts;     //!< 保存数据的时间戳
@property (nonatomic, strong) NSMutableArray<EFADevRealTimeDataItem *> *data;  //!< 多通道数据

// 自定义数据
@property (nonatomic, strong) NSMutableArray<EFADevRealTimeDataItem *> *filterData; //!< 过滤0通道之后剩余的通道数据
@property (nonatomic, readonly) NSString * tsStr;       //!< 时间戳字符串
@property (nonatomic, readonly) NSInteger heartRate;    ///< 心跳
@property (nonatomic, readonly) BOOL muteMode;          ///< 音响模式
@end

@interface EFADeviceInfoModel : NSObject
@property (nonatomic, strong) EFADeviceListItem *device_info;       //!< 设备信息
@property (nonatomic, strong) EFADevRealTimeData *realtime_data;    //!< 实时数据
@property (nonatomic, strong) NSArray<NSString *> *data_stream_list;//!< 当天0点往前n天的数据，zip压缩，需解压(当前存储的为Base64编码)

// 自定义数据
@property (nonatomic, strong) NSMutableArray<EFADevRealTimeData *> *unzipStream;    //!< 存储解压之后的数据(时间从小到大)
@property (nonatomic, strong) NSArray<EFADevPtCidItem *> *streamPtCidArray;  //!< 统计多少种参量
@property (nonatomic, strong) NSArray<NSString *> *timestampArray;           //!< 时间戳的数组

- (void)unzipStreamList;    //!< 解压数据
- (NSArray<NSNumber *> *)rtvArrayWithCid:(NSInteger)cid pt:(NSInteger)pt;    //!< 由pt和cid唯一确定某一个数据(已按参量转换)
@end


#pragma mark - 传输协议
extern NSString *const EFADeviceProtocolPtType;       //!< 参量类型的TypeId
extern NSString *const EFADeviceProtocolPtTitle;      //!< 参量类型的描述
extern NSString *const EFADeviceProtocolPtUnit;       //!< 参量类型的单位
extern NSString *const EFADeviceProtocolPtMultiple;   //!< 参量类型的倍数
extern NSString *const EFADeviceProtocolPtDecNum;     //!< 小数点的位数
extern NSString *const EFADeviceProtocolPtThvStart;   //!< 阈值起始值
extern NSString *const EFADeviceProtocolPtThvEnd;     //!< 阈值终止值
@interface EFADeviceProtocolModel : NSObject
@property (nonatomic, strong) NSArray *ptArray;         //!< 参量类型
@property (nonatomic, strong) NSArray *ptSwitchArray;   //!< 参量类型的补充(开关量的相关操作)
@property (nonatomic, strong) NSDictionary *stDics;     //!< 设备状态表
@property (nonatomic, strong) NSDictionary *sortStDics; //!< 归为7大类的状态表
@property (nonatomic, strong) NSArray *threeStArray;    //!< 再次归类为3种状态
@property (nonatomic, strong) NSArray *sysDevTypeArray; ///< 系统类型、设备类型对应表
@property (nonatomic, strong) NSArray<NSNumber *> *needInputSubUUIDArray; //!< 电气消防火灾报警系统需要用户输入设备从编码的设备类型

+ (instancetype)sharedInstance;
- (NSDictionary *)protocolInfoWithPt:(NSInteger)pt;
- (NSString *)stateDescribeWithSt:(NSInteger)st;
- (NSString *)sortStateDescribeWithSt:(NSInteger)st;
- (BOOL)isSwitchPt:(NSInteger)pt;
- (NSString *)rtvSwitchDescribeWithRtv:(NSInteger)rtv pt:(NSInteger)pt;
- (NSString *)thvSwitchDescribeWithThv:(NSInteger)thv pt:(NSInteger)pt;
- (NSArray<NSNumber *> *)thvRangeArrayWithPt:(NSInteger)pt; ///< 设置设备阈值时使用

/// 系统类型、设备类型相关
- (NSString *)deviceTypeDescribeWithType:(NSInteger)type;
- (BOOL)deviceTypeNeedSubUUIDWithType:(NSInteger)type;      ///< 查询电气消防火灾是否需要用户输入设备从编码
- (NSArray<NSDictionary *> *)deviceTypeArrayWithSystemTypeId:(NSInteger)sysTypeId;  ///< 根据系统类型找到设备类型

/// 红黄率三种状态的相关操作
- (NSString *)threeStateDescribeWithSt:(NSInteger)st;
- (NSString *)threeStateMapImgNameWithSt:(NSInteger)st;
- (NSString *)threeStateListImgNameWithSt:(NSInteger)st;
- (NSString *)threeStateColorWithSt:(NSInteger)st;
@end
